package org.csu.small.common;

import com.google.common.collect.Sets;

import java.util.Set;


public class Constant {
    public static final String LOGIN_USER = "loginUser";
    public static final String USERNAME = "username";
    public static final String EMAIL = "email";
    public static final String PHONE = "phone";
    public static final String PASSWORD = "password";
    public interface Role{
        int CUSTOMER = 0;//前台用户
        int ADMIN = 1;//后台管理
    }

    public interface Point{
        double ZERO = 0;//积分为0
    }

    public interface Slide{
        int SHOW = 1;//展示
        int NOTSHOW = 0;//不展示
    }

    public interface ProductListOrderBy{
        Set<String> PRICE_ASE_DESC = Sets.newHashSet("price_desc", "price_asc");
    }

    public enum ProductStatus{
        ON_SALE(0, "在售"),
        IN_STOCK(1,"有货"),
        OUT_OF_STOCK(2,"缺货"),
        OFF_SHELVES(-1,"下架");
        private int code;
        private String description;
        ProductStatus(int code, String description){
            this.code = code;
            this.description = description;
        }

        public int getCode() {
            return code;
        }

        public String getDescription() {
            return description;
        }

    }


    public interface Favorites {
        int CHECKED = 1; //选中
        int UN_CHECKED = 0; //未选中
    }

    public interface Cart{
        int CHECKED = 1; //购物车选中
        int UN_CHECKED = 0; //购物车未选中

        String LIMIT_NUM_SUCCESS = "LIMIT_NUM_SUCCESS";
        String LIMIT_NUM_FAILURE = "LIMIT_NUM_FAILURE";
    }

    public enum OrderStatus{
        CANCEL(0,"订单取消"),
        NONPAYMENT(10,"尚未支付"),
        PAYMENT(20,"已支付"),
        SEND(30,"已发货"),
        SUCCEEDED(40,"已收货"),
        CLOSED(50,"订单关闭");

        private int code;
        private String description;

        OrderStatus(int code,String description){
            this.code = code;
            this.description = description;
        }

        public int getCode() {
            return code;
        }
        public String getDescription() {
            return description;
        }

        public static OrderStatus codeOf(int code) {
            for (OrderStatus orderStatus : values()) {
                if (orderStatus.getCode() == code) {
                    return orderStatus;
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }
    }


    public interface AlipayCallback {
        String TRADE_STATUS_WAIT_BUYER_PAY = "WAIT_BUYER_PAY";//交易创建，等待买家付款
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS";//未支付交易超时关闭，或支付完成后全额退款

        //两个返回值
        String RESPONSE_SUCCESS = "success";//交易支付成功
        String RESPONSE_FAILED = "failed";//交易结束，不可退款
    }

    //作为以后扩展使用，比如接入微信支付等
    public enum PayPlatformEnum {
        ALIPAY(1, "支付宝");

        PayPlatformEnum(int code, String description) {
            this.code = code;
            this.description = description;
        }

        private int code;
        private String description;

        public int getCode() { return code; }
        public String getDescription() { return description; }



    }


    public enum PaymentTypeEnum {
        ONLINE_PAY(1, "在线支付");

        PaymentTypeEnum(int code, String description) {
            this.code = code;
            this.description = description;
        }

        private int code;
        private String description;

        public int getCode() { return code; }
        public String getDescription() { return description; }

        public static PaymentTypeEnum codeOf(int code) {
            for (PaymentTypeEnum paymentTypeEnum : values()) {
                if (paymentTypeEnum.getCode() == code) {
                    return paymentTypeEnum;
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }
    }
}
